#include "common.h"
#include "msn_user.h"

msn_user_t *msn_user_new(const char *passport)
{
	msn_user_t *user = g_slice_new0(msn_user_t);
	g_assert(user);
	if(passport)
		user->passport = g_string_new(passport);

	return user;
}

void msn_user_clean(msn_user_t *user)
{
	if(!user)
		return;
	g_string_free_safe(user->passport, 1);
	g_string_free_safe(user->store_name, 1);
	g_string_free_safe(user->display_name, 1);
	g_string_free_safe(user->statu_line, 1);
	g_slice_free(msn_user_t, user);
}

MSN_USER_LIST_TYPE msn_user_list_type_get(const char *str)
{
	g_return_val_if_fail(str!=NULL, 0);
	
	if(!strcasecmp(str, "Allow"))
		return MSN_USER_LIST_AL;
	else if(!strcasecmp(str, "Reverse"))
		return MSN_USER_LIST_RL;
	else if(!strcasecmp(str, "Pending"))
		return MSN_USER_LIST_PL;
	else 
		return MSN_USER_LIST_NONE;
}

const char * msn_user_list_type_string(MSN_USER_LIST_TYPE type)
{
	switch(type) {
		case MSN_USER_LIST_AL:
			return "Allow";
		case MSN_USER_LIST_PL:
			return "Pending";
		case MSN_USER_LIST_RL:
			return "Reverse";
		default:
			return "NONE";
	}
}
